package view;

import controller.StoreHouse;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Named;
import javax.inject.Inject;
import model.Gnome;

/**
 *This class is used to handle the file privilegedUser.xhtml
 * @author Guillaume, Yann
 */
@Named(value = "privilegedMarketManager")
@ConversationScoped
public class PrivilegedMarketManager implements Serializable {

    @EJB
    private StoreHouse storeHouse;
    @Inject
    private Conversation conversation;
    private int newNbrOfGnomeInTheStorehouse;
    private String newGnomeType;
    private int nbrNewGnomeAvailable;
    private Double newGnomePrice;

    /** 
     * Creates a new instance of PrivilegedMarketManager 
     */
    public PrivilegedMarketManager() {
    }
    
    /**
     * Start a conversation to store variable relative to the session
     */
    private void startConversation() {
        if (conversation.isTransient()) {
            conversation.begin();
        }
    }
    /**
     * This function can be used by a storehouse manager to set the new quantity of gnomes 
     * @param nbr new number of gnome to store
     */
    public void setNewNbrOfGnomeInTheStorehouse(int nbr) {
        this.newNbrOfGnomeInTheStorehouse = nbr;
    }
    /**
     * This function can be used by a storehouse manager to get to new quantity of gnomes
     * @return 
     */
    public int getNewNbrOfGnomeInTheStorehouse() {
        return this.newNbrOfGnomeInTheStorehouse;
    }
    /**
     * This function can be used to set a new type of gnome on the storehouse 
     * @param type 
     */
    public void setNewGnomeType(String type) {
        this.newGnomeType = type;
    }
    /**
     * this function can be used to get the new type of gnome
     * @return 
     */
    public String getNewGnomeType() {
        return this.newGnomeType;
    }
    /**
     * This function retrieves from the storehouse a list of gnomes 
     * @return 
     */
    public List<Gnome> getListOfAllGnome() {
        startConversation();
        List<Gnome> list = storeHouse.getListOfAllGnome();
        return list;
    }

    /**
     * This function allows a storehouse manager to change the quantity of gnomes of a given type store in the storehouse
     * @param type 
     */
    public void changedStrorehouseStock(String type) {
        storeHouse.changeStorehouseStock(type, newNbrOfGnomeInTheStorehouse);
    }

    /**
     * This function allows a storehouse manager to add a new type of gnome in the storehouse
     */
    public void addANewTypeOfGnomeInTheStorehouse() {
        storeHouse.addNewTypeOfGnome(newGnomeType, nbrNewGnomeAvailable, newGnomePrice);
    }

    /**
     * This function allows a storehouse manager to delete a type of gnome from the storehouse
     * @param type 
     */
    public void deleteGnomeTypeInTheStorehouse(String type) {
        storeHouse.deleteGnomeTypeX(type);
    }
    /**
     * This function can be used to set the number of gnomes available for the new type of gnomes
     * @param nbr 
     */
    public void setNbrNewGnomeAvailable(int nbr) {
        this.nbrNewGnomeAvailable = nbr;
    }
    /**
     * This function can be used to get the number of new gnomes available
     * @return 
     */
    public int getNbrNewGnomeAvailable() {
        return this.nbrNewGnomeAvailable;
    }

    /**
     * This function can be used to set the price for the new gnomes
     * @param price  new price for the gnome
     */
    public void setNewGnomePrice(Double price) {
        this.newGnomePrice = price;
    }

    /**
     * This function can be used to get the price for the new gnomes
     * @return return the price of the gnome
     */
    public Double getNewGnomePrice() {
        return newGnomePrice;
    }
}
